package com.cn.view;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MainFrame extends JFrame {
	private JPanel contentPane;
	private JDesktopPane desktopPane = null;

	/**
	 * Create the frame.
	 */
	public MainFrame() {
		setTitle("超市信息管理系统主界面");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 800, 600);

		JMenuBar menuBar = new JMenuBar();
		setJMenuBar(menuBar);

		JMenu mnNewMenu = new JMenu("信息管理");
		mnNewMenu.setIcon(new ImageIcon(MainFrame.class.getResource("/images/base.png")));
		menuBar.add(mnNewMenu);

		JMenu mnNewMenu_goods = new JMenu("商品管理");
		mnNewMenu_goods.setIcon(new ImageIcon(MainFrame.class.getResource("/images/goods.png")));
		JMenuItem menuItem_goods = new JMenuItem("商品信息管理");
		menuItem_goods.setIcon(new ImageIcon(MainFrame.class.getResource("/images/goods_goods.png")));
		menuItem_goods.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				GoodsManagement goodsManagement = new GoodsManagement();
				goodsManagement.setVisible(true);
				desktopPane.add(goodsManagement);
			}
		});
		mnNewMenu_goods.add(menuItem_goods);
        mnNewMenu.add(mnNewMenu_goods);

		JMenu mnNewMenu_1 = new JMenu("部门管理");
		mnNewMenu_1.setIcon(new ImageIcon(MainFrame.class.getResource("/images/department.png")));
		mnNewMenu.add(mnNewMenu_1);

		JMenuItem menuItem = new JMenuItem("添加部门");
		menuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				DepartmentAddFrame departmentAddFrame=new DepartmentAddFrame();
				departmentAddFrame.setVisible(true);
				desktopPane.add(departmentAddFrame);
			}
		});
		menuItem.setIcon(new ImageIcon(MainFrame.class.getResource("/images/add.png")));
		mnNewMenu_1.add(menuItem);

		JMenuItem menuItem_1 = new JMenuItem("维护部门");
		menuItem_1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				DepartmentManageFrame departmentManageFrame=new DepartmentManageFrame();
				departmentManageFrame.setVisible(true);
				desktopPane.add(departmentManageFrame);
			}
		});
		menuItem_1.setIcon(new ImageIcon(MainFrame.class.getResource("/images/edit.png")));
		mnNewMenu_1.add(menuItem_1);

		JMenu mnNewMenu_2 = new JMenu("员工管理");
		mnNewMenu_2.setIcon(new ImageIcon(MainFrame.class.getResource("/images/worker.png")));
		mnNewMenu.add(mnNewMenu_2);

		JMenuItem menuItem_2 = new JMenuItem("添加员工");
		menuItem_2.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				WorkerAddFrame workerAddFrame=new WorkerAddFrame();
				workerAddFrame.setVisible(true);
				desktopPane.add(workerAddFrame);
			}
		});

		menuItem_2.setIcon(new ImageIcon(MainFrame.class.getResource("/images/add.png")));
		mnNewMenu_2.add(menuItem_2);

		JMenuItem menuItem_3 = new JMenuItem("维护员工");
		menuItem_3.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				WorkerManageFrame workerManageFrame=new WorkerManageFrame();
				workerManageFrame.setVisible(true);
				desktopPane.add(workerManageFrame);
			}
		});
		menuItem_3.setIcon(new ImageIcon(MainFrame.class.getResource("/images/edit.png")));
		mnNewMenu_2.add(menuItem_3);

		JMenuItem menuItem_4 = new JMenuItem("退出系统");
		menuItem_4.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				int result=JOptionPane.showConfirmDialog(null, "是否退出系统？");
				if(result==0){
					dispose();
				}
			}
		});
		menuItem_4.setIcon(new ImageIcon(MainFrame.class.getResource("/images/exit.png")));
		mnNewMenu.add(menuItem_4);

		JMenu menu = new JMenu("关于系统");
		menu.setIcon(new ImageIcon(MainFrame.class.getResource("/images/about.png")));
		menuBar.add(menu);

		JMenuItem aboutJMenuItem = new JMenuItem("About");
		aboutJMenuItem.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				AboutFrame aboutFrame=new AboutFrame();
				aboutFrame.setVisible(true);
				desktopPane.add(aboutFrame);
			}
		});
		aboutJMenuItem.setIcon(new ImageIcon(MainFrame.class.getResource("/images/about.png")));
		menu.add(aboutJMenuItem);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new BorderLayout(0, 0));
		desktopPane = new JDesktopPane();
		contentPane.add(desktopPane, BorderLayout.CENTER);
		this.setExtendedState(JFrame.MAXIMIZED_HORIZ);
	}
}

